package elite.core.staffInfo.sub;

import com.wisdge.dataservice.Result;
import elite.core.dataBase.DBMethod;
import elite.core.dataBase.OneDBPara;
import elite.core.dataBase.StateRsObj;
import elite.core.dataBase.changeUpdateConn;
import elite.core.lang.LangRoot;
import elite.core.log.logCls;
import elite.core.log.logIF;
import elite.core.root.*;
import elite.core.staffInfo.OneStaff;
import elite.core.staffInfo.StaffManagerList;
import elite.core.staffInfo.iface.iStaffLoginChk;
import elite.core.staffInfo.other.LoginPara;
import elite.core.staffInfo.other.LoginReturn;
import elite.core.staffInfo.other.OneRole;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class StaffLoginChk implements iStaffLoginChk {
    private final static logIF log = logCls.getMe(StaffManagerList.class);

    private int CheckMobileFlag(String vNoStr, String mbFlag) {
        if (mbFlag.equals("MB")) {
            return 1;
        }
        if (PublicVar.getInstance().getOTConfig().getOneOT("loginMobileDisable").equals("1")) {
            return -1;
        }
        if (vNoStr == null) {
            return -1;
        }
        int iCount = vNoStr.length();
        if (iCount == 11) {
            for (int i = 0; i < iCount; i++) {
                String mTmp = vNoStr.substring(i, i + 1);
                if (mTmp.compareTo("0") >= 0 && mTmp.compareTo("9") <= 0) {
                } else {
                    log.debug("S:" + StaticMethod.getThreadID() + " No Mobile:" + vNoStr + " CharIndex:" + i);
                    return -1;
                }
            }
            return 1;
        } else {
            log.debug("S:" + StaticMethod.getThreadID() + " No Mobile:" + vNoStr + " Len <> 11");
            return -1;
        }

    }

    private Result getAgentIDByMobile(Connection conn, String vMobile, String vDBExt, String vEPID, String grpId, LogObj logk) {
        String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", vEPID, grpId, logk);
        String mStrSql;
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(vMobile, 0));

        if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
            mStrSql = "Select LOGINNAME,WORKSTATUS from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where MOBILE=? "; //and WORKSTATUS='ONLINE'
        } else {
            mStrSql = "Select AGENT_ID,WORKSTATUS from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where MOBILE=? ";  //and WORKSTATUS='ONLINE'
        }
        StateRsObj rs = DBMethod.getBoundRs(conn, mStrSql, sqlTypeList.systemSql, para, logk);
        //ResultSet mRec=DBMethod.getResultSet(vState, mStrSql,sqlTypeList.systemSql,logk);
        if (rs == null) {
            log.info(logk.getLogStr() + " sql do failed:" + mStrSql + " para:" + para.toString());
            return new Result(-3, "AGENTDBERROR ");
        }
        Result iFlag = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
        Result rt;
        if (iFlag.getCode() == 1) {
            rt = new Result(1, DBMethod.getStrValue(rs.getRs(), 1));
        } else {
            PublicRoot.getInstance().StaffWorkStatus(iFlag, conn, logk);
            rt = iFlag;
        }
        rs.closeMe();
        return rt;
	    /*
		String mTmpAgentID;
		if (DBMethod.RecNext(rs.getRs())){
			mTmpAgentID=DBMethod.getStrValue(rs.getRs(),1);
		}else{
			mTmpAgentID="";
			log.info(logk.getLogStr("Find One Staff Failed By Mobile:"+mStrSql));
		}
		rs.closeMe();
		return mTmpAgentID;*/
    }


    private String CheckUpdate(Connection readConn, Connection updateConn, String dbType, String dbExtStr, String runKey, String staffId, LogObj logk) {
        String mLoginKey = StaticMethod.getLoginKey(runKey);
        //
        //		Statement mState=DBMethod.CreateStatementUpdate(conn);
        //		if (mState==null){
        //			log.info(logk.getLogStr("Open Statement Failed: by Staff is Checkin Failed "));
        //			return "F";
        //		}
        //String mDBType=PublicVar.getInstance().getOneDBPoolType(mStaff.UseDBName("")).trim().toUpperCase();
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(StaticMethod.FormatLongToDateString(DBMethod.getDBNow(dbType, readConn, logk)), 2));
        para.add(new OneDBPara(mLoginKey, 0));

        String mSql = "Update WEBLOGINLIST" + dbExtStr.toUpperCase() + "  set CHECKDBTIME=? Where LOGINKEY=? ";
        String mResult;
        if (DBMethod.ExecBoundSql(updateConn, mSql, sqlTypeList.systemSql, para, logk).getCode() > 0) {
            mResult = "T";
        } else {
            log.debug(logk.getLogStr("没有更新到登录记录:" + mSql + " StaffID:" + staffId + " Key:" + runKey));
            mResult = "F";
        }
        log.debug(logk.getLogStr("Login Check Key:" + runKey + " Result:" + mResult));
        return mResult;
    }
    //	private String CheckinStaff(String vKey,String vRemoteIP){
    //		PublicRoot mPublicInfo= PublicRoot.getInstance();
    //		loggerWrite.info(vRemoteIP+" Staff Checkin:"+vKey);
    //		if (vKey==null){
    //			loggerWrite.info(vRemoteIP+" Staff Checkin Key is Nulls:"+vKey);
    //			return "F" ;
    //		}else  if (!(mPublicInfo.getPopInStr(vKey))) {
    //			loggerWrite.info(vRemoteIP+ " Staff is Checkin Failed:"+vKey);
    //			return "F" ;
    //		}else {
    //			OneStaff mStaff = mPublicInfo.getStaffInfo(vKey);
    //			if (mStaff==null){
    //				loggerWrite.info(vRemoteIP+ " Staff is Checkin Failed:"+vKey);
    //				return "F";
    //			}
    //			DataSource mDS=PublicVar.getInstance().getDataSource(mStaff.getdBMainKeyID());
    //			if (mDS==null){
    //				loggerWrite.info(vRemoteIP+ " Open DataSource Failed:"+mStaff.getdBMainKeyID()+" by Staff is Checkin Failed : "+vKey);
    //				return "F";
    //			}
    //			Connection mConn=DBMethod.getConnectWait(mDS);
    //			if (mConn==null){
    //				loggerWrite.info(vRemoteIP+ " Open Connection Failed:"+mStaff.getdBMainKeyID()+" by Staff is Checkin Failed : "+vKey);
    //				return "F";
    //			}
    //			String mDBType=PublicVar.getInstance().getOneDBPoolType(mStaff.UseDBName(""));
    //			String mResult=CheckUpdate(mConn,mDBType,mStaff.getdBExtStr(),vKey,mStaff.getStaffId(),vRemoteIP);
    //			DBMethod.CloseConnect(mConn);
    //			return mResult;
    //		}
    //	}


    //	LoginReturn mTmp=new LoginReturn();
    //	mTmp.setAgentId(agentId);		mTmp.setEpid(epid); 				mTmp.setEpName(epName);
    //	mTmp.setGroupId(groupId);		mTmp.setGroupName(groupName); 		mTmp.setLoginName(loginName);
    //	mTmp.setRemoteInfo(remoteInfo); mTmp.setRunKey(runKey);				mTmp.setStaffId(staffId);
    //	mTmp.setStaffName(staffName);	mTmp.setRoleList(roleList);
    //	return new Result(succFlag,"",mTmp);


    private void CheckStaffInfo(String LangStr, Result returndata, Connection readConn, Connection updateConn, String loginId, String vStaffID, String vDBExt, String vEPID, String vGrpId, String vPwd, String vUID, int vIngorePwd, LogObj logk) {
        if (vStaffID.equals(PublicVar.defaultSystemStaff)) {
            returndata.setCode(1);
            LoginReturn mTmp = (LoginReturn) returndata.getValue();
            mTmp.setAgentId(PublicVar.defaultSystemStaff);
            mTmp.setStaffId(PublicVar.defaultSystemStaff);
            mTmp.setStaffName(PublicVar.defaultSystemStaff);
            mTmp.setHeadimg("");
            mTmp.setIsSupervisor(1);
            return;
        } else if (vStaffID.equals(PublicVar.defaultCustStaff)) {
            returndata.setCode(1);
            LoginReturn mTmp = (LoginReturn) returndata.getValue();
            mTmp.setAgentId(PublicVar.defaultCustStaff);
            mTmp.setStaffId(PublicVar.defaultCustStaff);
            mTmp.setStaffName(PublicVar.defaultCustStaff);
            mTmp.setHeadimg("");
            mTmp.setIsSupervisor(1);
            return;
        }
        //		Statement mState=DBMethod.CreateStatementUpdate(conn);
        //		if (mState==null){
        //			log.info(logk.getLogStr("Open Statement Failed: by Staff is Checkin Failed "));
        //			returndata.setCode(-99);
        //			returndata.setMessage("CheckStaffInfo ，Statment Create Failed");
        //			return ;
        //		}
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(vStaffID, 0));

        String mStrSql = "Select AGENT_ID,STAFFNAME,PASSWORD,HEADIMG, ISSUPERVISOR,WRONGPWDCOUNT from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where STAFF_ID=? ";
        String mStrSqlUpdate = "Update STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " set WRONGPWDCOUNT=?,WRONGPWDDATE=? where STAFF_ID=? ";
        StateRsObj rs = DBMethod.getBoundRs(readConn, mStrSql, sqlTypeList.systemSql, para, logk);
        //ResultSet mRec=DBMethod.getResultSet(mState, mStrSql,sqlTypeList.systemSql,logk);
        int mFlag, mIsSuper, tryPwdTimes = 0;
        String mTmpName, mTmpPWD, mTmpAgentId, mHeadImg;
        if (DBMethod.RecNext(rs.getRs())) {
            mTmpAgentId = DBMethod.getStrValue(rs.getRs(), "AGENT_ID");
            mTmpName = DBMethod.getStrValue(rs.getRs(), "STAFFNAME");
            mTmpPWD = DBMethod.getStrValue(rs.getRs(), "PASSWORD");
            mHeadImg = DBMethod.getStrValue(rs.getRs(), "HEADIMG");
            mIsSuper = DBMethod.getIntValue(rs.getRs(), "ISSUPERVISOR");
            tryPwdTimes = DBMethod.getIntValue(rs.getRs(), "WRONGPWDCOUNT");
            mFlag = 1;
        } else {
            mTmpName = "";
            mTmpPWD = "";
            mTmpAgentId = "";
            mHeadImg = "";
            mIsSuper = 0;
            mFlag = 0;
        }
        log.debug(logk.getLogStr("Img ID:" + mHeadImg));
        rs.closeMe();
        if (PublicVar.getInstance().staffPwdTryTimes != 0) {
            if (tryPwdTimes == PublicVar.getInstance().staffPwdTryTimes) {
                returndata.setCode(-55);
                returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", logk) + PublicVar.getInstance().staffPwdTryTimes);
                returndata.setValue(vStaffID);
                tryPwdTimes++;
                List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                paraUp.add(new OneDBPara(String.valueOf(tryPwdTimes), 1));
                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                paraUp.add(new OneDBPara(vStaffID, 0));
                Result rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, sqlTypeList.systemSql, paraUp, logk);
                if (rsUp != null) {
                    log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                } else {
                    log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                }
                return;
            } else if (tryPwdTimes > PublicVar.getInstance().staffPwdTryTimes) {
                returndata.setCode(-56);
                returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", logk) + PublicVar.getInstance().staffPwdTryTimes);
                returndata.setValue(vStaffID);
                tryPwdTimes++;
                List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                paraUp.add(new OneDBPara(String.valueOf(tryPwdTimes), 1));
                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                paraUp.add(new OneDBPara(vStaffID, 0));
                Result rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, sqlTypeList.systemSql, paraUp, logk);
                if (rsUp != null) {
                    log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                } else {
                    log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                }
                return;
            }
        }
        if (mFlag == 0) {
            returndata.setCode(-5);
            returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chk", "密码认证错误：未找到对应的用户信息", logk));
        } else {
            if (vIngorePwd == 1) {
                returndata.setCode(1);
                LoginReturn mTmp = (LoginReturn) returndata.getValue();
                mTmp.setAgentId(mTmpAgentId);
                mTmp.setStaffId(vStaffID);
                mTmp.setStaffName(mTmpName);
                mTmp.setHeadimg(mHeadImg);
                mTmp.setIsSupervisor(mIsSuper);
            } else if (StaticMethod.PassWordCheck(loginId, mTmpPWD, vPwd, vUID, readConn, vEPID, vGrpId, logk) > 0) {
                returndata.setCode(1);
                LoginReturn mTmp = (LoginReturn) returndata.getValue();
                mTmp.setAgentId(mTmpAgentId);
                mTmp.setStaffId(vStaffID);
                mTmp.setStaffName(mTmpName);
                mTmp.setHeadimg(mHeadImg);
                mTmp.setIsSupervisor(mIsSuper);
                List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                paraUp.add(new OneDBPara("0", 1));
                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                paraUp.add(new OneDBPara(vStaffID, 0));
                Result rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, sqlTypeList.systemSql, paraUp, logk);
                if (rsUp != null) {
                    log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                } else {
                    log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                }
            } else {
                returndata.setCode(-5);
                returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chkpwd", "密码认证错误：密码错误 ", logk));
                tryPwdTimes++;
                List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                paraUp.add(new OneDBPara(String.valueOf(tryPwdTimes), 1));
                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                paraUp.add(new OneDBPara(vStaffID, 0));
                Result rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, sqlTypeList.systemSql, paraUp, logk);
                if (rsUp != null) {
                    log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                } else {
                    log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                }
            }
        }
    }

    private String getDefaultGrp(Connection conn, String vDBExt, String vStaff_ID, LogObj logk) {
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(vStaff_ID, 0));
        String mStrSql = "Select DEFAULTROLEGROUP from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + "    where STAFF_ID=? ";
        StateRsObj rs = DBMethod.getBoundRs(conn, mStrSql, sqlTypeList.systemSql, para, logk);
        //ResultSet mRs=DBMethod.getResultSet(vState, mStrSql,sqlTypeList.systemSql, logk);
        if (rs == null) {
            log.error(logk.getLogStr() + " 取默认组失败 STAFF_ID:" + vStaff_ID);
            return "";
        } else if (DBMethod.RecNext(rs.getRs())) {
            String mTmp = DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP");
            rs.closeMe();
            log.info(logk.getLogStr() + " 取默认组:" + mTmp + " STAFF_ID:" + vStaff_ID);
            return mTmp;
        } else {
            rs.closeMe();
            log.info(logk.getLogStr() + " 取默认组失败  STAFF_ID不存在:" + vStaff_ID);
            return "";
        }
    }

    private void setGroupInfo(Result returndata, Connection conn, String vStaff_ID, String groupId, String vDBExt, LogObj logk) {
        if (vStaff_ID.equals(PublicVar.defaultSystemStaff)) {
            LoginReturn mTmp = (LoginReturn) returndata.getValue();
            mTmp.setGroupId(PublicVar.defaultSystemStaff);
            mTmp.setGroupName(PublicVar.defaultSystemStaff);
            return;
        } else if (vStaff_ID.equals(PublicVar.defaultCustStaff)) {
            LoginReturn mTmp = (LoginReturn) returndata.getValue();
            mTmp.setGroupId(PublicVar.defaultCustStaff);
            mTmp.setGroupName(PublicVar.defaultCustStaff);
            return;
        }
        //		Statement mState=DBMethod.CreateStatementUpdate(conn);
        //		if (mState==null){
        //			log.info(logk.getLogStr("Open Statement Failed: by Staff is Checkin Failed "));
        //			returndata.setCode(-99);
        //			returndata.setMessage("setGroupInfo ，Statment Create Failed");
        //			return ;
        //		}
        if (groupId == null) {
            groupId = getDefaultGrp(conn, vDBExt, vStaff_ID, logk);
        } else if (groupId.trim().equals("")) {
            groupId = getDefaultGrp(conn, vDBExt, vStaff_ID, logk);
        }
        String mTmpName;
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(groupId, 0));
        String mStrSql = "select ROLEGROUPDESCRIPTION from ROLEGROUP" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where ROLEGROUP_ID=? ";
        StateRsObj rs = DBMethod.getBoundRs(conn, mStrSql, sqlTypeList.systemSql, para, logk);
        if (rs == null) {
            mTmpName = "";
        } else {
            mTmpName = rs.getFristOneValue();
            rs.closeMe();
        }


        //		ResultSet mRec=DBMethod.getResultSet(mState, mStrSql,sqlTypeList.systemSql,logk);
        //		if (DBMethod.RecNext(mRec)){
        //			mTmpName=DBMethod.getStrValue(mRec,"ROLEGROUPDESCRIPTION");
        //		}else{
        //			mTmpName="";
        //		}
        //		DBMethod.CloseResultSet(mRec);
        //		DBMethod.CloseStatement(mState);
        LoginReturn mTmp = (LoginReturn) returndata.getValue();
        mTmp.setGroupId(groupId);
        mTmp.setGroupName(mTmpName);
    }

    private void setOneStaffRoleList(Result returndata, Connection conn, String vDBExt, String staffId, LogObj logk) {
        if (staffId.equals(PublicVar.defaultSystemStaff)) {
            List<OneRole> mResultList = new LinkedList<OneRole>();
            LoginReturn mTmp = (LoginReturn) returndata.getValue();
            mTmp.setRoleList(mResultList);
            return;
        } else if (staffId.equals(PublicVar.defaultCustStaff)) {
            List<OneRole> mResultList = new LinkedList<OneRole>();
            LoginReturn mTmp = (LoginReturn) returndata.getValue();
            mTmp.setRoleList(mResultList);
            return;
        }
        //		Statement mState=DBMethod.CreateStatementUpdate(conn);
        //		if (mState==null){
        //			log.info(logk.getLogStr("Open Statement Failed: by Staff is Checkin Failed "));
        //			returndata.setCode(-99);
        //			returndata.setMessage("setOneStaffRoleList ，Statment Create Failed");
        //			return ;
        //		}
        List<OneRole> mResultList = new LinkedList<OneRole>();
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(staffId, 0));
        String mSql = "select A.ROLE_ID,A.ROLENAME,A.STATUS  from ROLE" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " A ,STAFFROLE" + StaticMethod.sqlTN(vDBExt) + " B where A.ROLE_ID=B.ROLE_ID AND B.STAFF_ID=? ";
        StateRsObj rs = DBMethod.getBoundRs(conn, mSql, sqlTypeList.systemSql, para, logk);
        //		String mSql="select b.rolegrouptype,b.rolegrouptypedesc from staffgrouptype a , sysc_rolegrouptype b where a.grouptype=b.rolegrouptype and a.staff_id='"+staffId+"'";
        //ResultSet mRec=DBMethod.getResultSet(mState, mSql,sqlTypeList.systemSql,logk);
        if (rs != null) {
            while (DBMethod.RecNext(rs.getRs())) {
                if (DBMethod.getIntValue(rs.getRs(), "STATUS") == 0) {

                } else {
                    mResultList.add(new OneRole(DBMethod.getStrValue(rs.getRs(), "ROLE_ID"), DBMethod.getStrValue(rs.getRs(), "ROLENAME")));
                }
            }
            rs.closeMe();
        }
        //		DBMethod.CloseResultSet(mRec);
        //		DBMethod.CloseStatement(mState);
        LoginReturn mTmp = (LoginReturn) returndata.getValue();
        mTmp.setRoleList(mResultList);
    }

    private Result getSuccLoginObj(LoginPara inPara, String vGrpId, String runKey, Connection ReadConn, Connection updateConn, String vDBKey, String epName, int epidNum, String staffId, int ingorePwd, int loginNum, String vRemoteIp, LogObj logk) {


        LoginReturn mTmpReturnValue = new LoginReturn();
        mTmpReturnValue.setEpid(inPara.getEpid());
        mTmpReturnValue.setEpName(epName);
        mTmpReturnValue.setEpId_Num(epidNum);
        mTmpReturnValue.setLoginTime(StaticMethod.getNowTimeBySql());
        if (inPara.getStandFlag() == 1) {
            mTmpReturnValue.setRunKey(runKey + "$" + vDBKey);
        } else {
            mTmpReturnValue.setRunKey(runKey + inPara.getEpid());
        }
        mTmpReturnValue.setOrdIndex(loginNum);
        mTmpReturnValue.setLoginName(inPara.getLoginId());
        mTmpReturnValue.setRemoteInfo(inPara.getRemoteInfo());
        Result mReturnData = new Result();
        mReturnData.setValue(mTmpReturnValue);
        CheckStaffInfo(inPara.getUseLang(), mReturnData, ReadConn, updateConn, inPara.getLoginId(), staffId, StaticMethod.getExtTB(inPara.getEpid()), inPara.getEpid(), vGrpId, inPara.getPassword(), inPara.getUid(), ingorePwd, logk);
        if (mReturnData.getCode() < 0) {//密码验证失败
            return mReturnData;
        } else {//密码验证成功
            String mDBType = PublicVar.getInstance().getOneDBPoolType(vDBKey, logk);
            String mResult = CheckUpdate(ReadConn, updateConn, mDBType, StaticMethod.getExtTB(inPara.getEpid()), runKey, staffId, logk);
            if (mResult.equals("T")) {
                setGroupInfo(mReturnData, ReadConn, staffId, vGrpId, StaticMethod.getExtTB(inPara.getEpid()), logk);
                setOneStaffRoleList(mReturnData, ReadConn, StaticMethod.getExtTB(inPara.getEpid()), staffId, logk);
                return mReturnData;
            } else {
                return null;
            }
        }
    }

    public Result CheckCanLogin(String vDBMain, LoginPara inPara, int clientFlag, LogObj logk) {
        DataSource mDs = PublicVar.getInstance().getDB(vDBMain, 1, logk);
        if (mDs == null) {
            log.info(logk.getLogStr("不能获取要登录的数据库:" + vDBMain));
            return new Result(-11, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDBPool", "不能获取要登录的数据库:", logk) + vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
        } else {
            Connection mConn = DBMethod.getConnectWait(mDs, logk);
            if (mConn == null) {
                log.info(logk.getLogStr("不能获取要登录的数据库连接信息:" + vDBMain));
                return new Result(-12, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDB", "不能获取要登录的数据库连接信息:", logk) + vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
            }
            //			Statement mStatement=DBMethod.CreateStatementReadOnlyNext(mConn);
            //			if (mStatement==null){
            //				log.info(logk.getLogStr("不能获取要登录的数据库连接信息Statement:"+vDBMain));
            //				DBMethod.CloseConnect(mConn, logk);
            //				return new Result(-12,"不能获取要登录的数据库连接信息Statement:"+vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
            //			}
            List<OneDBPara> para = new ArrayList<OneDBPara>();
            para.add(new OneDBPara(String.valueOf(clientFlag), 1));
            String mStrSql = "select count(*) from ( select distinct STAFF_ID,DBMAINKEYID from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " where CLIENTFLAG=? and STAFF_ID<>'" + PublicVar.defaultSystemStaff + "' and Staff_ID<>'" + PublicVar.defaultCustStaff + "' ) a where 1=1";
            StateRsObj rs = DBMethod.getBoundRs(mConn, mStrSql, sqlTypeList.systemSql, para, logk);
            //ResultSet mRec=DBMethod.getResultSet(mStatement, mStrSql,sqlTypeList.systemSql,logk);
            if (rs == null) {
                DBMethod.CloseConnect(mConn, logk);
                return new Result(-18, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.lincese", "lisence 检查失败", logk));
            }
            int mTmpCount;
            mTmpCount = StaticMethod.StringToInt(rs.getFristOneValue());
            //			if (DBMethod.RecNext(mRec)){
            //				mTmpCount=DBMethod.getIntValue(mRec, 1);
            //			}else{
            //				mTmpCount=0;
            //			}
            rs.closeMe();
            DBMethod.CloseConnect(mConn, logk);
            return new Result(1, "", mTmpCount);
        }
    }
    //	private int UpdateRemoteInfo(Connection vConn,String epID,String loginKey,String remoteInfo,LogObj logk){
    //
    //		String mStrSql="Upate WebLoginList"+StaticMethod.getExtTB(epID) +" Set LoginComputer='" + remoteInfo.replaceAll("'","''")+" Where LoginKey='"+loginKey.replaceAll("'","''")+"'";// And DefaultDBName='"+vLoginDBPool+"'";
    //		Statement mState=DBMethod.CreateStatementUpdate(vConn);
    //		if (mState==null){
    //			loggerWrite.info(logk.getLogStr()+" Update Remote Info Failed,Statment Create Failed");
    //			return -1;
    //		}
    //		int iUpdate=DBMethod.ExecSql(mState, mStrSql, logk);
    //		DBMethod.CloseStatement(mState);
    //		return iUpdate;
    //	}
    //	public Result loginDefaultAccount(String vDBMain, int vIngorePwd,LoginPara inPara,String vDBPool,
    //										String vGrpId, String epName,String vRemoteIp,LogObj logk) {
    //		if (inPara.getLoginId().equals(PublicVar.defaultSystemStaff)){
    //
    //		}else{
    //			return new Result(0);
    //		}
    //	}

    private Result CheckSub(Connection readConn, Connection updateConn, StateRsObj rs, String mLoginAgentId, String localIp, String localPort, String remoteIp, String vDBMain, int vIngorePwd, LoginPara inPara, String vDBPool, String vGrpId, String epName, int epidNum, String vRemoteIp, LogObj logk) {
        StringBuffer allToken = new StringBuffer();
        while (DBMethod.RecNext(rs.getRs())) {
            if (DBMethod.getIntValue(rs.getRs(), "CLIENTFLAG") == inPara.getClientFlag()) {
                String mStr = DBMethod.getStrValue(rs.getRs(), "LOGINKEY");
                if (inPara.getStandFlag() == 1) {
                    allToken.append(",").append(mStr + "$" + vDBMain);

                } else {
                    allToken.append(",").append(mStr + inPara.getEpid());
                }
                String mStafff_ID = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                int mLoginNum = DBMethod.getIntValue(rs.getRs(), "LOGNUM");
                if (DBMethod.getStrValue(rs.getRs(), "LOGINCOMPUTER").equals(inPara.getRemoteInfo())) {
                    if (DBMethod.getStrValue(rs.getRs(), "DEFAULTDBNAME").equalsIgnoreCase(vDBPool)) {
                        rs.closeMe();
                        Result mReturnData = getSuccLoginObj(inPara, vGrpId, mStr, readConn, updateConn, vDBMain, epName, epidNum, mStafff_ID, vIngorePwd, mLoginNum, vRemoteIp, logk);
                        if (mReturnData != null) {
                            //Statement state=DBMethod.CreateStatementUpdate(mConn);
                            //if (state!=null){
                            if (mReturnData.getCode() > 0) {
                                String mDBType = PublicVar.getInstance().getOneDBPoolType(vDBMain, logk).trim().toUpperCase();
                                //StaticMethod.FormatLongToDateString(DBMethod.getDBNow(mDBType, mConn,logk))
                                List<OneDBPara> para2 = new ArrayList<OneDBPara>();
                                para2.add(new OneDBPara(StaticMethod.FormatLongToDateString(DBMethod.getDBNow(mDBType, readConn, logk)), 2));
                                para2.add(new OneDBPara(localIp, 0));
                                para2.add(new OneDBPara(localPort, 0));
                                para2.add(new OneDBPara(remoteIp, 0));
                                para2.add(new OneDBPara(mStr, 0));
                                String mSql = "Update WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  set CHECKDBTIME=?,SERVERIP=?,SERVERPORT=?,CLIENTIP=? Where LOGINKEY=? ";
                                Result mResult = DBMethod.ExecBoundSql(updateConn, mSql, sqlTypeList.systemSql, para2, logk);   // DBMethod.ExecSql(state, mSql,sqlTypeList.systemSql,logk);//PublicVar.getInstance().getDataSource(vDBMain,0,logk)
                                if (mResult.getCode() > 0) {
                                    //OneStaff mStaffInfo =PublicRoot.getInstance().getStaffInfo(mToken,logk);
									/*if (ePID.equals("")){
									  	this.log_LoginKey=vLoginKey+"$"+dBMainKeyID;
								  }else{
									  this.log_LoginKey=vLoginKey+vEPID;
								  }*/


                                    LoginReturn mTmpReturnValue = (LoginReturn) mReturnData.getValue();
                                    OneStaff mStaffInfo = PublicRoot.getInstance().getStaffInfo(mTmpReturnValue.getRunKey(), logk);
                                    log.debug(logk.getLogStr() + " DO SQL ReInsert His:" + mStaffInfo.reInsertHis(updateConn, localIp, localPort, remoteIp, logk));

                                } else {
                                    log.info(logk.getLogStr() + " DO SQL　失败:" + mSql + " Key:" + mStr);
                                }
                            }
                            //DBMethod.CloseStatement(state);
                            //}
                        }
                        if (mReturnData == null) {
                            log.debug(logk.getLogStr("再次登录    ID:" + mStr + " Result:无登录信息  --" + inPara.toString()));
                            return null;//new Result(-1,  "再次登录失败 Result:无登录信息");
                        } else {
                            log.debug(logk.getLogStr("再次登录    ID:" + mStr + " Result:" + mReturnData.getCode() + " -- " + inPara.toString()));
                            return mReturnData;
                        }
                    }
                } else {//不同机器登录
                    String mTmpRead = "重复登录系统 :DBPool" + vDBPool + " Computer:" + DBMethod.getStrValue(rs.getRs(), "LOGINCOMPUTER") + "--" + DBMethod.getStrValue(rs.getRs(), "DEFAULTDBNAME") + " -- " + inPara.toString();
                    while (DBMethod.RecNext(rs.getRs())) {
                        if (DBMethod.getIntValue(rs.getRs(), "CLIENTFLAG") == inPara.getClientFlag()) {
                            mStr = DBMethod.getStrValue(rs.getRs(), "LOGINKEY");
                            if (inPara.getStandFlag() == 1) {
                                allToken.append(",").append(mStr + "$" + vDBMain);
                            } else {
                                allToken.append(",").append(mStr + inPara.getEpid());
                            }
                        }
                    }
                    rs.closeMe();
                    log.debug(logk.getLogStr("IP:" + vRemoteIp + " " + mTmpRead));
                    LoginReturn mTmpReturnValue = new LoginReturn();
                    mTmpReturnValue.setOrdIndex(mLoginNum);
                    Result mReturnData = new Result();
                    mReturnData.setValue(mTmpReturnValue);
                    CheckStaffInfo(inPara.getUseLang(), mReturnData, readConn, updateConn, mLoginAgentId, mStafff_ID, StaticMethod.getExtTB(inPara.getEpid()), inPara.getEpid(), vGrpId, inPara.getPassword(), inPara.getUid(), vIngorePwd, logk);
                    if (mReturnData.getCode() < 0) {//密码验证失败
                        log.debug(logk.getLogStr("IP:" + vRemoteIp + " 密码错 ," + mTmpRead));
                        return new Result(-7, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.reLogin", "重复登录系统", logk), "");
                    } else {
                        if (inPara.getStandFlag() == 1) {
                            return new Result(-7, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.reLogin", "重复登录系统", logk), allToken.substring(1)); //mStr+"$"+vDBMain
                        } else {
                            return new Result(-7, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.reLogin", "重复登录系统", logk), allToken.substring(1)); //mStr+inPara.getEpid()
                        }
                    }
                }
            }
        }
        return null;
    }

    public Result CheckLoginStaffFormDB(int isStaffId, String localIp, String localPort, String remoteIp, String vDBMain, int vIngorePwd, LoginPara inPara, String vDBPool, String vGrpId, String epName, int epidNum, String vRemoteIp, LogObj logk) {
        DataSource mDs = PublicVar.getInstance().getDB(vDBMain, 1, logk);
        if (mDs == null) {
            log.error(logk.getLogStr("不能获取要登录的数据库:" + vDBMain));
            return new Result(-11, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDBPool", "不能获取要登录的数据库:", logk) + vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
        } else {
            Connection mConnCur = DBMethod.getConnectWait(mDs, logk);
            if (mConnCur == null) {
                log.error(logk.getLogStr("不能获取要登录的数据库连接信息:" + vDBMain));
                return new Result(-12, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDB", "不能获取要登录的数据库连接信息:", logk) + vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
            }
            String mStrSql, mLoginAgentID;
            List<OneDBPara> para1 = new ArrayList<OneDBPara>();
            if (isStaffId == 1) {
                para1.add(new OneDBPara(inPara.getLoginId(), 0));
                mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where STAFF_ID=? ";// And DefaultDBName='"+vLoginDBPool+"'";
                mLoginAgentID = "";
            } else {
                if (CheckMobileFlag(inPara.getLoginId(), vRemoteIp) > 0) {
                    Result getStf = getAgentIDByMobile(mConnCur, inPara.getLoginId(), StaticMethod.getExtTB(inPara.getEpid()), inPara.getEpid(), vGrpId, logk);
                    if (getStf.getCode() > 0) {
                        mLoginAgentID = getStf.getMessage();
                        log.debug(logk.getLogStr("Check Old Staff Mobile:" + inPara.getLoginId() + " Agent_ID/loginname:" + mLoginAgentID));
                    } else {
                        return getStf;
                    }
                } else {
                    mLoginAgentID = inPara.getLoginId();
                }
                if (inPara.getLoginId().startsWith("#S#S#")) {
                    para1.add(new OneDBPara(mLoginAgentID, 0));
                    mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where AGENT_ID=? ";// And DefaultDBName='"+vLoginDBPool+"'";
                } else {
                    if (PublicVar.getInstance().getSqlCase() == 1) {
                        para1.add(new OneDBPara(mLoginAgentID.trim(), 0));
                        mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where  AGENT_ID=? ";// And DefaultDBName='"+vLoginDBPool+"'";
                    } else {
                        para1.add(new OneDBPara(mLoginAgentID.trim().toUpperCase(), 0));
                        mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where upper(AGENT_ID)=? ";// And DefaultDBName='"+vLoginDBPool+"'";
                    }
                }
            }
            //	DBMethod.QuerySqlToList(conn, sql, maxRows, sqlType, logk)
            StateRsObj rsobj = DBMethod.getBoundRs(mConnCur, mStrSql, sqlTypeList.systemSql, para1, logk);
            //ResultSet mRec=DBMethod.getResultSet(mStatement, mStrSql,sqlTypeList.systemSql,logk);
            if (rsobj == null) {
                log.error(logk.getLogStr("不能获取要登录的表(WebLoginList):" + vDBMain));
                DBMethod.CloseConnect(mConnCur, logk);
                return new Result(-1, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.webtb", "不能获取要登录的表(WebLoginList):", logk) + vDBMain);  //new LoginResult("", vEPID, -1,"-1", "不能获取要登录的表(WebLoginList):"+vDBMain, "", "","","","","","",vStandFlag);
            } else {
				/*String[] flist={"%CLIENTFLAG","LOGINKEY","STAFF_ID","%LOGNUM","LOGINCOMPUTER","DEFAULTDBNAME"};
				List<Map<String,Object>> data=DBMethod.readAllData(rsobj.getRs(),flist , logk);*/
                changeUpdateConn upDB = new changeUpdateConn(vDBMain, mConnCur, logk);
                Result rt = CheckSub(mConnCur, upDB.getCurConn(), rsobj, mLoginAgentID, localIp, localPort, remoteIp, vDBMain, vIngorePwd, inPara, vDBPool, vGrpId, epName, epidNum, vRemoteIp, logk);
                rsobj.closeMe();
                DBMethod.CloseConnect(mConnCur, logk);
                upDB.CloseDBConn(logk);
                return rt;
				/*
				rs.closeMe();*/
                //DBMethod.CloseResultSet(mRec);DBMethod.CloseStatement(mStatement);

            }
        }
    }

    private Result checkStaffExists(int isStaffId, Connection conn, String loginId, String grpId, String remoteIP, LogObj logk) {
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        String strsql;
        if (isStaffId == 1) {
            para.add(new OneDBPara(loginId, 0));
            strsql = "select WORKSTATUS from  STAFF F where F.STAFF_ID=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;// F.WORKSTATUS='ONLINE'    and
        } else if (CheckMobileFlag(loginId, remoteIP) > 0) {
            para.add(new OneDBPara(loginId.trim(), 0));
            strsql = "select WORKSTATUS from  STAFF F where F.MOBILE=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;// F.WORKSTATUS='ONLINE'    and
        } else {
            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", grpId, logk);
            Result newID = StaffManagerList.autoSelectStaff(conn, mPara, loginId, "", grpId, logk);

            if (PublicVar.getInstance().getSqlCase() == 1) {
                if (newID.getCode() > 0) {
                    para.add(new OneDBPara(newID.getMessage(), 0));
                } else {
                    para.add(new OneDBPara(loginId.trim(), 0));
                }
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select WORKSTATUS from  STAFF F where  F.LOGINNAME =? ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'    and
                } else {
                    strsql = "select WORKSTATUS from  STAFF F where  F.AGENT_ID =? ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'   and
                }
            } else {
                if (newID.getCode() > 0) {
                    para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                } else {
                    para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                }
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select WORKSTATUS from  STAFF F where  upper(F.LOGINNAME)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'    and
                } else {
                    strsql = "select WORKSTATUS from  STAFF F where   upper(F.AGENT_ID)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'   and
                }
            }

        }
        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, sqlTypeList.systemSql, para, logk);
        if (rs == null) {
            return new Result(-3, "AGENTDBERROR ");
        }
        Result iFlag = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
        Result rt;
        if (iFlag.getCode() == 1) {
            rt = new Result(1);
        } else {
            PublicRoot.getInstance().StaffWorkStatus(iFlag, conn, logk);
            rt = iFlag;
        }
        rs.closeMe();
        return rt;

    }

    private void InsertLastLoginRole(Connection conn, String staffId, String groupId, LogObj logk) {
        DBMethod.ExecSql(conn, "Delete from STAFFLOGINGRPHIS  Where STAFF_ID='" + staffId + "'", sqlTypeList.rptSystem, logk);
        DBMethod.ExecSql(conn, "Insert into STAFFLOGINGRPHIS  ( STAFF_ID,LOGINGROUPID) values ('" + staffId + "','" + groupId + "')", sqlTypeList.rptSystem, logk);
    }

    private Result selectOneGroupID(String langStr, Connection conn, String staffId, String dbExt, LogObj logk) {
        String strsql = "select ROLEGROUP_ID from STAFFROLEGROUP" + dbExt + " where STAFF_ID=?";
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(staffId, 0));
        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, sqlTypeList.systemSql, para, logk);
        Result rt;
        if (DBMethod.RecNext(rs.getRs())) {
            rt = new Result(1, DBMethod.getStrValue(rs.getRs(), "ROLEGROUP_ID"));
            InsertLastLoginRole(conn, staffId, rt.getMessage(), logk);
        } else {
            rt = new Result(-65, LangRoot.getInstance().getMsg(langStr, "staff.pwd.loggrp", "未获取到对应组", logk));
        }
        rs.closeMe();
        return rt;
    }

    private Result getStaff_MGNT_ORG_CODE(Connection conn, String loginId, String dbExt, String remoteIP, LogObj logk) {
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        String strsql;
        if (loginId.startsWith("#S#S#")) {
            para.add(new OneDBPara(loginId.substring(5), 0));
            //DEFAULTROLEGROUP from STAFF"+dBExtStr+" where STAFF_ID
            strsql = "select STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from STAFF" + dbExt + " F where STAFF_ID=? ";//And F.WORKSTATUS='ONLINE' ";
        } else if (CheckMobileFlag(loginId, remoteIP) > 0) {
            para.add(new OneDBPara(loginId.trim(), 0));
            strsql = "select STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where F.MOBILE=? ";// And F.WORKSTATUS='ONLINE' ";
        } else {
            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", "", logk);
            if (PublicVar.getInstance().getSqlCase() == 1) {
                para.add(new OneDBPara(loginId.trim(), 0));
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where  F.LOGINNAME =? ";//  And F.WORKSTATUS='ONLINE' ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'    and
                } else {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where  F.AGENT_ID =?  ";//And F.WORKSTATUS='ONLINE' ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'   and
                }
            } else {
                para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where  upper(F.LOGINNAME)=? ";// And F.WORKSTATUS='ONLINE'  ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'    and
                } else {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where   upper(F.AGENT_ID)=?  ";//And F.WORKSTATUS='ONLINE' ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'   and
                }
            }
        }
        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, sqlTypeList.systemSql, para, logk);
        if (rs == null) {
            return new Result(-3, "AGENTDBERROR ");
        }
        Result rt = new Result(-4, "no Agent");
        String GroupID = "";
        while (DBMethod.RecNext(rs.getRs())) {
            //Staff_ID=DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
            if ("ONLINE".equalsIgnoreCase(DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"))) {
                GroupID = DBMethod.getStrValue(rs.getRs(), "MGNT_ORG_CODE");
                rt = new Result(1, GroupID);
            } else {
                if (rt.getCode() != 1) {
                    rt = new Result(-19, DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"));
                }
            }
        }
        rs.closeMe();
        return rt;
    }

    public Result CheckStaffIP(String loginId, String dbExt, String remoteIP, String currentIP, DataSource ds, LogObj logk) {
        if (loginId.equalsIgnoreCase(PublicVar.defaultCustStaff) || loginId.equalsIgnoreCase(PublicVar.defaultSystemStaff)) {
            return new Result(1, "");
        }
        Connection conn = DBMethod.getConnectWait(ds, logk);
        if (conn == null) {
            return new Result(-11, "数据连接获取失败");
        }
        Result rs = getStaff_MGNT_ORG_CODE(conn, loginId, dbExt, remoteIP, logk);
        DBMethod.CloseConnect(conn, logk);
        if (rs.getCode() > 0) {
            return IPCheck.DBCheckIn(ds, rs.getMessage(), currentIP, logk);
        } else {
            return rs;
        }
    }

    public Result autoSelectGrp(String loginStr, int isStaffId, Connection conn, String loginId, String dbExt, String remoteIP, LogObj logk) {
        if (loginId.equalsIgnoreCase(PublicVar.defaultCustStaff) || loginId.equalsIgnoreCase(PublicVar.defaultSystemStaff)) {
            return new Result(1, "");
        }
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        String strsql;
        if (isStaffId == 1) {
            para.add(new OneDBPara(loginId, 0));
            strsql = "select STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from STAFF" + dbExt + " F where STAFF_ID=?  ";// And F.WORKSTATUS='ONLINE' ";
        } else if (loginId.startsWith("#S#S#")) {
            para.add(new OneDBPara(loginId.substring(5), 0));
            //DEFAULTROLEGROUP from STAFF"+dBExtStr+" where STAFF_ID
            strsql = "select STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from STAFF" + dbExt + " F where STAFF_ID=?  ";//And F.WORKSTATUS='ONLINE' ";
        } else if (CheckMobileFlag(loginId, remoteIP) > 0) {
            para.add(new OneDBPara(loginId.trim(), 0));
            strsql = "select STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where F.MOBILE=?  ";// And F.WORKSTATUS='ONLINE' ";
        } else {
            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", "", logk);
            if (PublicVar.getInstance().getSqlCase() == 1) {
                para.add(new OneDBPara(loginId.trim(), 0));
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where  F.LOGINNAME =?  ";//  And F.WORKSTATUS='ONLINE' ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'    and
                } else {
                    strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where  F.AGENT_ID =?   ";//And F.WORKSTATUS='ONLINE' ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'   and
                }
            } else {
                para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where  upper(F.LOGINNAME)=?   ";//And F.WORKSTATUS='ONLINE'  ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'    and
                } else {
                    strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where   upper(F.AGENT_ID)=?  ";// And F.WORKSTATUS='ONLINE' ";//And ='" +vKey.replaceAll("'","''")+"'" ;//F.WORKSTATUS='ONLINE'   and
                }
            }
        }
        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, sqlTypeList.systemSql, para, logk);
        if (rs == null) {
            return new Result(-3, "AGENTDBERROR ");
        }
        Result rt = new Result(-4, "no Agent");
        String Staff_ID = "", GroupID = "";
        while (DBMethod.RecNext(rs.getRs())) {
            if ("ONLINE".equalsIgnoreCase(DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"))) {
                Staff_ID = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                GroupID = DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP");
                rt = new Result(1);
            } else {
                if (rt.getCode() != 1) {
                    rt = new Result(-19, DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"));
                }
            }
        }
        rs.closeMe();
        if (rt.getCode() < 0) {
            return rt;
        }
        strsql = "select LOGINGROUPID from STAFFLOGINGRPHIS" + dbExt + " where STAFF_ID=?";
        para = new ArrayList<OneDBPara>();
        para.add(new OneDBPara(Staff_ID, 0));
        rs = DBMethod.getBoundRs(conn, strsql, sqlTypeList.systemSql, para, logk);
        if (rs == null) {
            log.error(logk.getLogStr() + "话务员历史登录组表查询失败,sql:" + strsql);
            return new Result(-66, LangRoot.getInstance().getMsg(loginStr, "staff.pwd.his", "话务员历史登录组表查询失败", logk));
        }
        if (DBMethod.RecNext(rs.getRs())) {
            rt = new Result(1, DBMethod.getStrValue(rs.getRs(), "LOGINGROUPID"));
            rs.closeMe();
        } else {
            rs.closeMe();
            if ("".equals(GroupID.trim())) {
                //随机选择一个组
                rt = selectOneGroupID(loginStr, conn, Staff_ID, dbExt, logk);
            } else {
                rt = new Result(1, GroupID);
            }
        }
        return rt;
    }

    public Result checkStaffHasGrpId(String langStr, int isStaffId, Connection conn, String loginId, String grpId, String remoteIP, LogObj logk) {
        if (loginId.equalsIgnoreCase(PublicVar.defaultCustStaff) || loginId.equalsIgnoreCase(PublicVar.defaultSystemStaff)) {
            return new Result(1);
        }
        if (loginId.startsWith("#S#S#")) {
            return new Result(1); //LoginId 为staff_ID
        }
        Result rsFF = checkStaffExists(isStaffId, conn, loginId, grpId, remoteIP, logk);
        if (rsFF.getCode() < 0) {
            return rsFF;
        }
        String strsql;
        List<OneDBPara> para = new ArrayList<OneDBPara>();
        if (isStaffId == 1) {
            return new Result(1);
            //	para.add(new OneDBPara(grpId, 0));
            //	para.add(new OneDBPara(loginId.trim(), 0));
            //	strsql="select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID   And S.ROLEGROUP_ID=? and F.STAFF_ID=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;and F.WORKSTATUS='ONLINE'
        } else if (CheckMobileFlag(loginId, remoteIP) > 0) {
            para.add(new OneDBPara(grpId, 0));
            para.add(new OneDBPara(loginId.trim(), 0));
            strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID   And S.ROLEGROUP_ID=? and F.MOBILE=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;and F.WORKSTATUS='ONLINE'
        } else {
            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", grpId, logk);
            Result newID = StaffManagerList.autoSelectStaff(conn, mPara, loginId, "", grpId, logk);
            if (PublicVar.getInstance().getSqlCase() == 1) {
                if (newID.getCode() > 0) {
                    para.add(new OneDBPara(grpId, 0));
                    para.add(new OneDBPara(newID.getMessage(), 0));
                } else {
                    para.add(new OneDBPara(grpId, 0));
                    para.add(new OneDBPara(loginId.trim(), 0));
                }
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And  S.ROLEGROUP_ID=? and  F.LOGINNAME =? ";//And ='" +vKey.replaceAll("'","''")+"'" ; and F.WORKSTATUS='ONLINE'
                } else {
                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And S.ROLEGROUP_ID=? and F.AGENT_ID =? ";//And ='" +vKey.replaceAll("'","''")+"'" ; and F.WORKSTATUS='ONLINE'
                }
            } else {
                if (newID.getCode() > 0) {
                    para.add(new OneDBPara(grpId, 0));
                    para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                } else {
                    para.add(new OneDBPara(grpId, 0));
                    para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                }
                if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And  S.ROLEGROUP_ID=? and upper(F.LOGINNAME)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ; and F.WORKSTATUS='ONLINE'
                } else {
                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And S.ROLEGROUP_ID=? and upper(F.AGENT_ID)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ; and F.WORKSTATUS='ONLINE'
                }
            }

        }
        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, sqlTypeList.systemSql, para, logk);
        if (rs == null) {
            return new Result(-23, LangRoot.getInstance().getMsg(langStr, "staff.pwd.grpInfo", "检查登录组信息失败", logk));
        }
        Result iFlag = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
        Result rt;
        if (iFlag.getCode() == 1) {
            rt = new Result(1);
        } else {
            PublicRoot.getInstance().StaffWorkStatus(iFlag, conn, logk);
            rt = iFlag;
        }
        rs.closeMe();
        return rt;
		/*else if (!DBMethod.RecNext(rs.getRs())){
			rs.closeMe();
			return new Result(-23, "检查登录组信息失败,无对应登录组");
		}else {
			int count=DBMethod.getIntValue(rs.getRs(),1);
			rs.closeMe();
			if (count>0) {
				return new Result(1);
			}else {
				return new Result(-23, "检查登录组信息失败,无对应登录组");
			}
		}*/
        //		String rsStr=DBMethod.getResultSetFirstValue(conn, strsql, logk);
        //		if (rsStr.equals("")) {
        //			return new Result(-23, "检查登录组信息失败");
        //		}else if ( rsStr)
    }

    private Result loginRtData(Connection readConn, Connection updateConn, String updateSql, LoginPara inPara, StateRsObj rs, String grpId, String epName, int epidNum, LogObj logk) {
        Result mReturnData = new Result();
        mReturnData.setCode(1);
        LoginReturn mTmpReturnValue = new LoginReturn();
        mReturnData.setValue(mTmpReturnValue);
        mTmpReturnValue.setEpid(inPara.getEpid());
        mTmpReturnValue.setEpName(epName);
        mTmpReturnValue.setEpId_Num(epidNum);
        mTmpReturnValue.setLoginName(inPara.getLoginId());
        mTmpReturnValue.setRemoteInfo(inPara.getRemoteInfo());
        mTmpReturnValue.setStaffId(DBMethod.getStrValue(rs.getRs(), "STAFF_ID"));
        mTmpReturnValue.setStaffName(DBMethod.getStrValue(rs.getRs(), "STAFFNAME"));
        mTmpReturnValue.setAgentId(DBMethod.getStrValue(rs.getRs(), "AGENT_ID"));
        mTmpReturnValue.setHeadimg(DBMethod.getStrValue(rs.getRs(), "HEADIMG"));
        mTmpReturnValue.setIsSupervisor(DBMethod.getIntValue(rs.getRs(), "ISSUPERVISOR"));
        mTmpReturnValue.setLoginTime(StaticMethod.getNowTimeString());
        if (grpId == null) {
            mTmpReturnValue.setGroupId(DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP"));
            log.debug(logk.getLogStr() + " Login Staff Get DefaultGroup:" + mTmpReturnValue.getGroupId() + " Input Group is null");
        } else if (grpId.trim().equals("")) {
            mTmpReturnValue.setGroupId(DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP"));
            log.debug(logk.getLogStr() + " Login Staff Get DefaultGroup:" + mTmpReturnValue.getGroupId() + " Input Group is Empty");
        } else {
            mTmpReturnValue.setGroupId(grpId);
        }
        rs.closeMe();
        setGroupInfo(mReturnData, readConn, mTmpReturnValue.getStaffId(), mTmpReturnValue.getGroupId(), StaticMethod.getExtTB(inPara.getEpid()), logk);
        setOneStaffRoleList(mReturnData, readConn, StaticMethod.getExtTB(inPara.getEpid()), mTmpReturnValue.getStaffId(), logk);
        //DBMethod.CloseConnect(mConn,mLogk);
        List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
        paraUp.add(new OneDBPara("0", 1));
        paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
        //paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
        if (PublicVar.getInstance().getSqlCase() == 1) {
            paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
        } else {
            paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
        }
        if (updateSql.length() > 0) {
            Result rsUp = DBMethod.ExecBoundSql(updateConn, updateSql, sqlTypeList.systemSql, paraUp, logk);
            if (rsUp != null) {
                log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
            } else {
                log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
            }
        }
        return mReturnData;
    }

    private Result loginOneSubStaff(int isStaffId, Connection readConn, Connection updateConn, String vDBMain, int vIngorePwd, LoginPara inPara, String vGrpId, String epName, int epidNum, String vRemoteIp, LogObj mLogk) {
        int empty = -1, dateExprie = -1;
        String mMinLevel = DBMethod.getParametersSqlEPID(readConn, "PWDRUL", inPara.getEpid(), vGrpId, mLogk);
        if (!mMinLevel.trim().equals("")) {
            List<String> arr = StaticMethod.stringToArr(mMinLevel, ",");//mMinLevel.indexOf(",");
            if (arr.size() > 2) {
                empty = StaticMethod.StringToInt(arr.get(2));
            }
            if (arr.size() > 3) {
                dateExprie = StaticMethod.StringToInt(arr.get(3));
            }
        }
        try {
            String mStrSql, mUpdateSql;
            List<OneDBPara> para = new ArrayList<OneDBPara>();
            if (isStaffId == 1) {
                para.add(new OneDBPara(inPara.getLoginId(), 0));
                mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.STAFF_ID=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;S.WORKSTATUS='ONLINE'  And
                mUpdateSql = "";
                log.info(mLogk.getLogStr("Login Info Sql:" + mStrSql + " Para:" + para.toString() + "  " + inPara.toString()));
                StateRsObj rs = DBMethod.getBoundRs(readConn, mStrSql, sqlTypeList.systemSql, para, mLogk);
                //ResultSet mRec=DBMethod.getResultSet(mStatement, mStrSql,sqlTypeList.systemSql,mLogk);
                if (rs == null) {
                    log.debug(mLogk.getLogStr(" Sql:" + mStrSql + " :AGENTDBERROR " + inPara.toString()));
                    return new Result(-3, "AGENTDBERROR ");
                }
                if (DBMethod.RecNext(rs.getRs())) {
                    return loginRtData(readConn, updateConn, mUpdateSql, inPara, rs, vGrpId, epName, epidNum, mLogk);
                } else {
                    rs.closeMe();
                    return new Result(-3, "StaffId 不存在 ");
                }
            }
            if (inPara.getLoginId().startsWith("#S#S#")) {
                para.add(new OneDBPara(inPara.getLoginId().substring(5), 0));
                mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.EWU_ID=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;S.WORKSTATUS='ONLINE'  And
                mUpdateSql = "";
            } else if (CheckMobileFlag(inPara.getLoginId(), vRemoteIp) > 0) {
                para.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.MOBILE=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;  S.WORKSTATUS='ONLINE'  And
                mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And MOBILE=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
            } else {
                String mPara = DBMethod.getParametersSqlEPID(readConn, "LOGNAM", inPara.getEpid(), vGrpId, mLogk);
                Result newID = StaffManagerList.autoSelectStaff(readConn, mPara, inPara.getLoginId().trim(), inPara.getEpid(), vGrpId, mLogk);
                if (PublicVar.getInstance().getSqlCase() == 1) {
                    if (newID.getCode() > 0) {
                        para.add(new OneDBPara(newID.getMessage(), 0));
                        inPara.setLoginId(newID.getMessage());
                    } else {
                        para.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                    }
                    if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                        mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.LOGINNAME =? ";//And ='" +vKey.replaceAll("'","''")+"'" ;S.WORKSTATUS='ONLINE'  And
                        mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And  LOGINNAME =? ";
                    } else {
                        mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where S.AGENT_ID=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;S.WORKSTATUS='ONLINE'  And
                        mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And AGENT_ID=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
                    }
                } else {
                    if (newID.getCode() > 0) {
                        para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                        inPara.setLoginId(newID.getMessage());
                    } else {
                        para.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                    }
                    if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                        mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  upper(S.LOGINNAME)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;S.WORKSTATUS='ONLINE'  And
                        mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And upper(LOGINNAME)=? ";
                    } else {
                        mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  upper(S.AGENT_ID)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;S.WORKSTATUS='ONLINE'  And
                        mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And upper(AGENT_ID)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
                    }
                }
            }
            log.info(mLogk.getLogStr("Login Info Sql:" + mStrSql + " Para:" + para.toString() + "  " + inPara.toString()));
            StateRsObj rs = DBMethod.getBoundRs(readConn, mStrSql, sqlTypeList.systemSql, para, mLogk);
            //ResultSet mRec=DBMethod.getResultSet(mStatement, mStrSql,sqlTypeList.systemSql,mLogk);
            if (rs == null) {
                log.debug(mLogk.getLogStr(" Sql:" + mStrSql + " :AGENTDBERROR " + inPara.toString()));
                return new Result(-3, "AGENTDBERROR ");
            }
            Result iFlag = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
            if (iFlag.getCode() == 1) {
                //	rs.closeMe();
            } else {
                log.debug(mStrSql + " :NOAGENT Or Not ONLINE " + inPara.toString() + " RS:" + iFlag.toString());
                rs.closeMe();
                PublicRoot.getInstance().StaffWorkStatus(iFlag, readConn, mLogk);
                return iFlag;
            }
            int pwdTryTimes = DBMethod.getIntValue(rs.getRs(), "WRONGPWDCOUNT");
            //	    	String TRYTimeStr=DBMethod.getParametersSqlEPID(readConn, "TRYPWD",inPara.getEpid(),vGrpId,mLogk);
            //	    	int trysTimes;
            //	    	if (t)
            if (PublicVar.getInstance().staffPwdTryTimes != 0) {
                if (pwdTryTimes == PublicVar.getInstance().staffPwdTryTimes) {
                    log.debug(mLogk.getLogStr("密码认证错误：已经超过最大重试次数：" + PublicVar.getInstance().staffPwdTryTimes));
                    String outStaffId = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                    rs.closeMe();
                    pwdTryTimes++;
                    List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                    paraUp.add(new OneDBPara(String.valueOf(pwdTryTimes), 1));
                    paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                    if (PublicVar.getInstance().getSqlCase() == 1) {
                        paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                    } else {
                        paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                    }
                    if (mUpdateSql.length() > 0) {
                        Result rsUp = DBMethod.ExecBoundSql(updateConn, mUpdateSql, sqlTypeList.systemSql, paraUp, mLogk);
                        if (rsUp != null) {
                            log.debug(mLogk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                        } else {
                            log.debug(mLogk.getLogStr() + " Update TryTimes Result is Null");
                        }
                    }
                    return new Result(-55, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", mLogk) + PublicVar.getInstance().staffPwdTryTimes, outStaffId);
                } else if (pwdTryTimes > PublicVar.getInstance().staffPwdTryTimes) {
                    log.debug(mLogk.getLogStr("密码认证错误：已经超过最大重试次数：" + PublicVar.getInstance().staffPwdTryTimes));
                    String outStaffId = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                    rs.closeMe();
                    pwdTryTimes++;
                    List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                    paraUp.add(new OneDBPara(String.valueOf(pwdTryTimes), 1));
                    paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                    //paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                    if (PublicVar.getInstance().getSqlCase() == 1) {
                        paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                    } else {
                        paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                    }
                    if (mUpdateSql.length() > 0) {
                        Result rsUp = DBMethod.ExecBoundSql(updateConn, mUpdateSql, sqlTypeList.systemSql, paraUp, mLogk);
                        if (rsUp != null) {
                            log.debug(mLogk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                        } else {
                            log.debug(mLogk.getLogStr() + " Update TryTimes Result is Null");
                        }
                    }
                    return new Result(-56, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", mLogk) + PublicVar.getInstance().staffPwdTryTimes, outStaffId);
                }
            }
            if (empty == 1 && DBMethod.getStrValue(rs.getRs(), "PASSWORD").equals("")) {
                log.debug(mLogk.getLogStr("密码不能为空 :" + vDBMain));
                rs.closeMe();
                //DBMethod.CloseConnect(mConn,mLogk);
                return new Result(-101, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.isEmpty", "密码不能为空:", mLogk) + vDBMain);
            }
            //StaticMethod.PassWordCheck(DBMethod.getStrValue(mRec, "Password"), vPwd,mConn)==1
            log.debug("登录者DB登录信息:" + rs.getRs().isFirst());
            if (StaticMethod.PassWordCheck(inPara.getLoginId(), DBMethod.getStrValue(rs.getRs(), "PASSWORD"), inPara.getPassword(), inPara.getUid(), readConn, inPara.getEpid(), vGrpId, mLogk) > 0 || vIngorePwd == 1) {
                if (dateExprie > 0 && vIngorePwd != 1) {//过期验证
                    log.debug("登录者最后密码修改时间:" + DBMethod.getStrValue(rs.getRs(), "PWDMODIFY"));

                    log.debug("登录者最后密码修改时间 rs.getRs().getDate():" + rs.getRs().getDate("PWDMODIFY"));
                    log.debug("登录者最后密码修改时间 rs.getRs().getTime():" + rs.getRs().getTime("PWDMODIFY"));
                    log.debug("登录者最后密码修改时间 rs.getRs().getObject():" + rs.getRs().getObject("PWDMODIFY"));
                    log.debug("登录者最后密码修改时间 rs.getRs().getObject():" + rs.getRs().getObject("PWDMODIFY").toString());

                    Date mModifyDate = DBMethod.getStrDate(rs.getRs(), "PWDMODIFY");
                    if (mModifyDate == null) {
                        log.debug(mLogk.getLogStr("密码过期，密码无修改时间"));
                        rs.closeMe();
                        return new Result(-103, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.expire", "密码过期，密码无修改时间", mLogk));
                    } else {
                        Date mNow = new Date(System.currentTimeMillis());
                        long day = (mNow.getTime() - mModifyDate.getTime()) / (86400000L);
                        if (day > dateExprie) {
                            log.debug(mLogk.getLogStr("密码过期，密码已经" + day + " 天未修改"));
                            rs.closeMe();
                            return new Result(-102, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.change1", "密码过期，密码已经", mLogk) + day + LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.change2", " 天未修改", mLogk));
                        }
                    }
                }
                return loginRtData(readConn, updateConn, mUpdateSql, inPara, rs, vGrpId, epName, epidNum, mLogk);
                //mTmpReturnValue.setRunKey(runKey);
                //				Result mReturnData=new Result();
                //				mReturnData.setCode(1);
                //				LoginReturn mTmpReturnValue=new LoginReturn();
                //				mReturnData.setValue(mTmpReturnValue);
                //				mTmpReturnValue.setEpid(inPara.getEpid());								mTmpReturnValue.setEpName(epName);
                //				mTmpReturnValue.setLoginName(inPara.getLoginId());						mTmpReturnValue.setRemoteInfo(inPara.getRemoteInfo());
                //				mTmpReturnValue.setStaffId(DBMethod.getStrValue(rs.getRs(), "STAFF_ID"));		mTmpReturnValue.setStaffName(DBMethod.getStrValue(rs.getRs(), "STAFFNAME"));
                //				mTmpReturnValue.setAgentId(DBMethod.getStrValue(rs.getRs(), "AGENT_ID"));		mTmpReturnValue.setHeadimg(DBMethod.getStrValue(rs.getRs(), "HEADIMG"));
                //				mTmpReturnValue.setIsSupervisor(DBMethod.getIntValue(rs.getRs(), "ISSUPERVISOR"));
                //				if (vGrpId==null){
                //					mTmpReturnValue.setGroupId(DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP"));
                //					log.debug(mLogk.getLogStr()+" Login Staff Get DefaultGroup:"+mTmpReturnValue.getGroupId()+" Input Group is null");
                //				}else if (vGrpId.trim().equals("")){
                //					mTmpReturnValue.setGroupId(DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP"));
                //					log.debug(mLogk.getLogStr()+" Login Staff Get DefaultGroup:"+mTmpReturnValue.getGroupId()+" Input Group is Empty");
                //				}else{
                //					mTmpReturnValue.setGroupId(vGrpId);
                //				}
                //				rs.closeMe();
                //				setGroupInfo(mReturnData, readConn,mTmpReturnValue.getStaffId(), mTmpReturnValue.getGroupId(), StaticMethod.getExtTB(inPara.getEpid()), mLogk);
                //				setOneStaffRoleList(mReturnData, readConn, StaticMethod.getExtTB(inPara.getEpid()), mTmpReturnValue.getStaffId(), mLogk);
                //				//DBMethod.CloseConnect(mConn,mLogk);
                //				List<OneDBPara> paraUp=new ArrayList<OneDBPara>();
                //				paraUp.add(new OneDBPara("0", 1));
                //				paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                //				//paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                //				if (PublicVar.getInstance().getSqlCase()==1) {
                //					paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                //				}else {
                //					paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                //				}
                //				if (mUpdateSql.length()>0) {
                //					Result rsUp= DBMethod.ExecBoundSql(updateConn, mUpdateSql, sqlTypeList.systemSql, paraUp,mLogk);
                //					if (rsUp!=null) {
                //						log.debug(mLogk.getLogStr()+ " Update TryTimes Result:"+rsUp.toString());
                //					}else {
                //						log.debug(mLogk.getLogStr()+ " Update TryTimes Result is Null");
                //					}
                //				}

            } else {
                rs.closeMe();
                log.debug(mStrSql + " :密码错误" + inPara.toString());
                pwdTryTimes++;
                List<OneDBPara> paraUp = new ArrayList<OneDBPara>();
                paraUp.add(new OneDBPara(String.valueOf(pwdTryTimes), 1));
                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                //paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                if (PublicVar.getInstance().getSqlCase() == 1) {
                    paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                } else {
                    paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                }
                if (mUpdateSql.length() > 0) {
                    Result rsUp = DBMethod.ExecBoundSql(updateConn, mUpdateSql, sqlTypeList.systemSql, paraUp, mLogk);
                    if (rsUp != null) {
                        log.debug(mLogk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                    } else {
                        log.debug(mLogk.getLogStr() + " Update TryTimes Result is Null");
                    }
                }
                return new Result(-5, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.err", "密码错误 ", mLogk));
            }

        } catch (Error e) {
            log.error(mLogk.getLogStr() + " StaffLogin Check Connect Failed 1", e);
            //DBMethod.CloseConnect(mConn,mLogk);
            return new Result(-6, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.error", "异常错误  ", mLogk));
        } catch (Exception e1) {
            log.error(mLogk.getLogStr() + " StaffLogin Check Connect Failed 2 ", e1);
            //DBMethod.CloseConnect(mConn,mLogk);
            return new Result(-6, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.error", "异常错误  ", mLogk));
        }
    }

    public Result LoginOneStaff(int isStaffId, String vDBMain, int vIngorePwd, LoginPara inPara, String vGrpId, String epName, int epIdNum, String vRemoteIp, LogObj mLogk) {
        //	String mLogHead="S:"+StaticMethod.getThreadID();
        //	LogObj mLogk=new LogObj("LoginStaff","","");

        changeUpdateConn mDB = new changeUpdateConn(vDBMain, mLogk);
        if (mDB.getNewConnFlag() < 0) {
            log.info(mLogk.getLogStr("不能获取要登录的数据库:" + vDBMain));
            return new Result(-11, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDBPool", "不能获取要登录的数据库:", mLogk) + vDBMain);
        } else {
            Result rt;
            try {
                rt = loginOneSubStaff(isStaffId, mDB.getReadConn(), mDB.getCurConn(), vDBMain, vIngorePwd, inPara, vGrpId, epName, epIdNum, vRemoteIp, mLogk);
            } catch (Error e) {
                log.info(mLogk.getLogStr() + " 登录异常:" + e.toString());
                rt = new Result(-1, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.loginerr", "登录异常", mLogk) + e.toString());
            } catch (Exception e) {
                log.info(mLogk.getLogStr() + " 登录异常:" + e.toString());
                rt = new Result(-1, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.loginerr", "登录异常", mLogk) + e.toString());
            } finally {
                mDB.CloseDBConn(mLogk);
            }
            return rt;
        }

		/*DataSource mDs=PublicVar.getInstance().getDataSource(vDBMain,1,mLogk);
		if (mDs==null){
			log.info(mLogk.getLogStr("不能获取要登录的数据库:"+vDBMain));
			return new Result(-11,"不能获取要登录的数据库:"+vDBMain);
		}else{

			Connection mConn =DBMethod.getConnectWait(mDs,mLogk);
			if (mConn==null){
				log.info(mLogk.getLogStr("不能获取要登录的数据库连接信息:"+vDBMain));
				return new Result(-12,"不能获取要登录的数据库连接信息:"+vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
			}

			Result rt;
			try {
				rt=loginOneSubStaff(mConn, vDBMain, vIngorePwd, inPara, vGrpId, epName, vRemoteIp, mLogk);
			}catch(Error e) {
				log.info(mLogk.getLogStr()+" 登录异常:"+e.toString());
				rt= new Result(-1,"登录异常"+e.toString());
			}catch(Exception e) {
				log.info(mLogk.getLogStr()+" 登录异常:"+e.toString());
				rt= new Result(-1,"登录异常"+e.toString());
			}finally {
				DBMethod.CloseConnect(mConn, mLogk);
			}
			return rt;
//			Statement mStatement=DBMethod.CreateStatementReadOnlyNext(mConn);
//			if (mStatement==null){
//				log.info(mLogk.getLogStr("不能获取要登录的数据库连接信息Statement:"+vDBMain));
//				DBMethod.CloseConnect(mConn,mLogk);
//				return new Result(-12,"不能获取要登录的数据库连接信息Statement:"+vDBMain);  // new LoginResult("", vEPID, -1, "-1","不能获取要登录的数据库:"+vDBMain, "", "","","","","","",vStandFlag);
//			}

		//	DBMethod.CloseStatement(mStatement);
			//DBMethod.CloseConnect(mConn);
//			String mOneStaffKey = StaticMethod.getGUID();
//			OneStaff mOneStaff = new OneStaff(mDs,"", mOneStaffKey,mStaffID,vLoginGroup,StaticMethod.getNowTimeString(),
//						  					  vLoginComputer, mStrResult,mReturnAgent_ID ,vDBPool,mTmpMain,vClientFlag,1);
//			if (mOneStaff.getLoginSuccFlag()==1){
//				mTmpReturnValue.setRunKey(mOneStaffKey);
//				if (inPara.getClientFlag()>9){
//					loggerWrite.info("Client Flag > 9 Jump Chche Staff Flag:"+ inPara.getClientFlag()+" LoginStaff:"+inPara.getLoginId());
//				}else{
//					allLoginStaff.put(mOneStaffKey, mOneStaff);
//				}
//				return new LoginResult(mOneStaffKey, "", 1,"","","","","",mStaffID, mStrResult,"",mTmpMain,1);
//			}else{
//				LoggerWrite.info("Staff Login  :Other登录记录插入失败:"+mStaffID);
//				return new LoginResult("", "", -1,"-1","登录记录插入失败", "","","","","","","",1);// "Other登录记录插入失败";
//			}
		}*/

    }

    public Result Logoutstaff(String langStr, String vDBMain, String vTBExtStr, String vEPID, String grpId, String loginId, String password, String vUID, String vRemoteIp, LogObj mLogk) {
        //String mLogHead="S:"+StaticMethod.getThreadID()+" T:"+loginId;
        if (loginId.equals(PublicVar.defaultSystemStaff)) {
            if (password.equals(PublicVar.getInstance().getDefaultStaffPwd())) {
                return new Result(1);
            } else {
                return new Result(-1, "用户密码错误");
            }
        } else if (loginId.equals(PublicVar.defaultCustStaff)) {
            if (password.equals(PublicVar.getInstance().getDefaultCustPwd())) {
                return new Result(1);
            } else {
                return new Result(-1, "用户密码错误");
            }
        }
        //LogObj mLogk=new LogObj("logout","","");
        DataSource mDS = PublicVar.getInstance().getDB(vDBMain, 1, mLogk);
        if (mDS == null) {
            log.info(mLogk.getLogStr() + " 不能获取要登录的数据库:" + vDBMain);
            return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.genDBPool", "不能获取要登录的数据库:", mLogk) + vDBMain);
        }
        Connection mConn = DBMethod.getConnectWait(mDS, mLogk);
        if (mConn == null) {
            log.info(mLogk.getLogStr() + " 不能获取要登录的数据库连接:" + vDBMain);
            return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.genDB", "不能获取要登录的数据连接:", mLogk) + vDBMain);
        }
        //		Statement mStatement =DBMethod.CreateStatementReadOnlyNext(mConn);
        //		if (mStatement==null){
        //			log.info(mLogk.getLogStr()+" 不能获取要登录的数据库连接Statment:"+vDBMain);
        //			DBMethod.CloseConnect(mConn,mLogk);
        //			return new Result(-1,"不能获取要登录的数据库连接Statment:"+vDBMain);
        //		}
        //
        try {
            String mStrSql;
            List<OneDBPara> para = new ArrayList<OneDBPara>();
            if (CheckMobileFlag(loginId, vRemoteIp) > 0) {
                para.add(new OneDBPara(loginId.trim(), 0));
                mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "  Where WORKSTATUS='ONLINE' And MOBILE=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
            } else {
                String mPara = DBMethod.getParametersSqlEPID(mConn, "LOGNAM", vEPID, grpId, mLogk);
                Result newID = StaffManagerList.autoSelectStaff(mConn, mPara, loginId, vEPID, grpId, mLogk);
                if (PublicVar.getInstance().getSqlCase() == 1) {
                    if (newID.getCode() > 0) {
                        para = new ArrayList<OneDBPara>();
                        para.add(new OneDBPara(newID.getMessage(), 0));
                        loginId = newID.getMessage();
                    } else {
                        para.add(new OneDBPara(loginId.trim(), 0));
                    }
                    if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                        mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "   Where WORKSTATUS='ONLINE' And  LOGINNAME =? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
                    } else {
                        mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "  Where WORKSTATUS='ONLINE' And  AGENT_ID =? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
                    }
                } else {
                    if (newID.getCode() > 0) {
                        para = new ArrayList<OneDBPara>();
                        para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                        loginId = newID.getMessage();
                    } else {
                        para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                    }
                    if (StaticMethod.StringToInt(mPara) == 1 || mPara.trim().equalsIgnoreCase("Y")) {
                        mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "   Where WORKSTATUS='ONLINE' And upper(LOGINNAME)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
                    } else {
                        mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "  Where WORKSTATUS='ONLINE' And upper(AGENT_ID)=? ";//And ='" +vKey.replaceAll("'","''")+"'" ;
                    }
                }
            }
            String mStaff_ID, mTmpPwd = "";
            StateRsObj rs = DBMethod.getBoundRs(mConn, mStrSql, sqlTypeList.systemSql, para, mLogk);

            //ResultSet mRec=DBMethod.getResultSet(mStatement, mStrSql,sqlTypeList.systemSql,mLogk);
            if (rs == null) {
                mStaff_ID = "";
            } else if (!DBMethod.RecNext(rs.getRs())) {
                mStaff_ID = "";
            } else {
                mStaff_ID = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                mTmpPwd = DBMethod.getStrValue(rs.getRs(), "PASSWORD");
            }
            //				if ( DBMethod.getStrValue(mRec,"Password").equalsIgnoreCase(password)){
            //			}
            //				mStaff_ID=DBMethod.getStrValue(mRec, "Staff_ID");
            //			}else{
            //				mStaff_ID="";
            //			}
            rs.closeMe();
            if (!mStaff_ID.equals("")) {
                if (StaticMethod.PassWordCheck(loginId, mTmpPwd, password, vUID, mConn, vEPID, grpId, mLogk) > 0) {
                    DBMethod.CloseConnect(mConn, mLogk);
                    return new Result(1, mStaff_ID);
                } else {
                    log.debug(mLogk.getLogStr() + " 用户密码错误");
                    DBMethod.CloseConnect(mConn, mLogk);
                    return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.usepwd", "用户密码错误", mLogk));
                }
            } else {
                DBMethod.CloseConnect(mConn, mLogk);
                log.debug(mLogk.getLogStr() + " 登出的用户未找到：" + mStrSql);
                ;
                return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.usernf", "用户未找到", mLogk));
            }
        } catch (Exception e) {
            log.error("PublicClassData Connection Failed", e);
            DBMethod.CloseConnect(mConn, mLogk);
            return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.userout", "登出异常错误 ", mLogk));
        }
    }


}
